package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseListData;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Comment;
import com.cskaoyan.model.bo.CommentBO;
import com.cskaoyan.model.bo.ReplyBO;
import com.cskaoyan.service.CommentService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.sun.javafx.event.BasicEventDispatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    @RequestMapping("list")
    public BaseRespVo list(Integer page,Integer limit,String sort,String order) throws JsonProcessingException {
        BaseListData data = commentService.list(page,limit,sort,order);
        return BaseRespVo.ok(data);
    }
    @RequestMapping("reply")
    public BaseRespVo reply(@RequestBody ReplyBO replyBO)
    {
        int res = commentService.reply(replyBO);
        return BaseRespVo.ok();
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody CommentBO commentBO)
    {
        int res = commentService.delete(commentBO);
        if(res == 1){
            return BaseRespVo.ok();
        }else{
            return BaseRespVo.fail("失败了");
        }
    }
}
